package com.sesame.listener;

import com.sesame.defin.Response;
import com.sesame.entity.User;
import com.sesame.feign.FeignServiceUser;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@CommonsLog
@Component
@CanalTable(value = "t_user")
public class UserHandler implements EntryHandler<User> {

    @Autowired
    FeignServiceUser feignServiceUser;

    @Override
    public void insert(User user) {
        //重新加载缓存
//        skuFeign.updateTypeItems(User.getType());
        log.info("add:"+user);
    }

    /****
     * 数据库修改数据，执行该方法
     */
    @Override
    public void update(User before, User after) {
        log.info("update before:"+before);
        log.info("update after:"+after);
        Response<User> res =  feignServiceUser.updateCacheDetail(after.getId());
        System.out.println(res);
        System.out.println();
    }

    /****
     * 数据库删除数据，执行该方法
     */
    @Override
    public void delete(User user) {
        log.info("del:"+user);
    }
}
